package org.jsola.hr.helper;

import org.jsola.hr.dto.CompanyAddDTO;
import org.jsola.hr.dto.CompanyUpdateDTO;
import org.jsola.hr.entity.CompanyDO;
import org.jsola.hr.query.CompanyQuery;
import org.jsola.hr.service.ICompanyService;
import org.jsola.hr.vo.CompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 用工单位
 *
 * @author zhr
 */
@Component
public class CompanyTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICompanyService companyService;

    /**
     * 生成add测试数据
     * @return CompanyAddDTO
     */
    public CompanyAddDTO getCompanyAddDTO(){
        CompanyAddDTO companyAddDTO = new CompanyAddDTO();
        companyAddDTO.setName(getRandomValue("varchar",100));
        companyAddDTO.setIndustry(getRandomValue("varchar",100));
        companyAddDTO.setAdministratorUserIds(getRandomValue("text",2147483647));
        companyAddDTO.setLogo(getRandomValue("varchar",100));
        companyAddDTO.setBusinessScope(getRandomValue("varchar",500));
        companyAddDTO.setProfile(getRandomValue("varchar",500));
        companyAddDTO.setLegalPerson(getRandomValue("varchar",20));
        companyAddDTO.setAddress(getRandomValue("varchar",100));
        companyAddDTO.setPersonSize(getRandomValue("varchar",50));
        companyAddDTO.setClientLevel(getRandomValue("varchar",64));
        companyAddDTO.setClientPhone(getRandomValue("varchar",64));
        companyAddDTO.setOfficialWebsite(getRandomValue("varchar",100));
        companyAddDTO.setTelephone(getRandomValue("varchar",50));
        companyAddDTO.setEmail(getRandomValue("varchar",50));
        companyAddDTO.setServerAnnex(getRandomValue("text",1000));
        return companyAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CompanyUpdateDTO
     */
    public CompanyUpdateDTO getCompanyUpdateDTO(CompanyVO companyVO){
        return companyService.selectDOById(companyVO.getId(), SITE_ID).to(CompanyUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CompanyQuery
     */
    public CompanyQuery getCompanyQuery() {
        CompanyQuery companyQuery = new CompanyQuery();
        List<CompanyDO> companyDOList = companyService.list(new CompanyDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(companyDOList)) {
            CompanyDO companyDO = companyDOList.get(0);
            companyQuery = companyDO.to(CompanyQuery.class);
        }
        return companyQuery;
    }

    /**
     * 保存示例
     * @return CompanyVO
     */
    public CompanyVO saveCompanyExample(){
        CompanyAddDTO addDTO = this.getCompanyAddDTO();
        CompanyVO companyVO = companyService.save(addDTO,buildTokenUser());
        return companyVO;
    }


}

